home *** CD-ROM | disk | FTP | other *** search
/ Alde ADA 1: #1 / CCCC 8804 Volume 1 Number 1 - Alde.iso / C / MISC / FUNC / PROFF.ARC / MAP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-21  |  1.4 KB  |  74 lines

  1. #include <stdio.h>
  2. /*
  3.  * map every character of s1 that is specified in s2
  4.  * into s3 and replace in s. (source s1 remains untouched)
  5.  */
  6.  
  7. map(s, s1, s2, s3)
  8. register char *s;
  9. register char *s1;
  10. register char *s2;
  11. register char *s3;
  12. {
  13.    char *t, *t1;
  14.  
  15.    if (*s1 != '\0')
  16.    {
  17.       t = s;
  18.       t1 = s1;
  19.       strcpy(t, t1);
  20.  
  21.       while (*s2 != '\0' && *s3 != '\0')
  22.       {
  23.          while (*t1 != '\0')
  24.          {
  25.             if (*t1 == *s2)
  26.                *t = *s3;
  27.             t++;
  28.             t1++;
  29.          }
  30.          t = s;
  31.          t1 = s1;
  32.          s2++;
  33.          s3++;
  34.       }
  35.    }
  36.    else
  37.       *s = '\0';
  38. }
  39.  
  40. /*
  41.  * roman - convert a numeric string into roman numerals
  42.  *
  43.  * icon version:
  44.  *procedure roman(n)
  45.  * local arabic, result
  46.  * static equiv
  47.  * initial equiv := ["","I","II","III","IV","V","VI","VII","VIII","IX"]
  48.  * integer(n) > 0 | fail
  49.  * result := ""
  50.  * every arabic := !n do
  51.  *    result := map(result,"IVXLCDM","XLCDM**") || equiv[arabic+1]
  52.  * if find("*",result) then fail else return result
  53.  * end
  54.  *
  55.  */
  56. int cvtroman(num, rom)
  57. char *num;
  58. char *rom;
  59. {
  60.    char tmp[20];
  61.  
  62.    static char *equiv_U[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};
  63.  
  64.    *rom = NULL;
  65.    while (*num != '\0')
  66.    {
  67.       map(tmp, rom, "IVXLCDM", "XLCDM**");
  68.       strcpy(rom, tmp);
  69.       strcat(rom, equiv_U[*num - '0']);
  70.       num++;
  71.    }
  72.    return (strlen(rom));
  73. }
  74.